package com.itheima.charset;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * @author Anomaly
 * @date 2023/2/8 17:07
 */
public class CharsetDemo {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s = "abc呵呵";
        byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
        byte[] bytes1 = s.getBytes(StandardCharsets.ISO_8859_1);
        byte[] bytes2 = s.getBytes(StandardCharsets.US_ASCII);
        byte[] bytes3 = s.getBytes(StandardCharsets.UTF_16);
        byte[] bytes4 = s.getBytes(StandardCharsets.UTF_16BE);
        byte[] bytes5 = s.getBytes("GBK");
        System.out.println(Arrays.toString(bytes));
        System.out.println(Arrays.toString(bytes1));
        System.out.println(Arrays.toString(bytes2));
        System.out.println(Arrays.toString(bytes3));
        System.out.println(Arrays.toString(bytes4));
        System.out.println(Arrays.toString(bytes5));
        System.out.println("===========================================");
        System.out.println(new String(bytes, StandardCharsets.UTF_8));
        System.out.println(new String(bytes1, StandardCharsets.ISO_8859_1));
        System.out.println(new String(bytes2, StandardCharsets.US_ASCII));
        System.out.println(new String(bytes3, StandardCharsets.UTF_16));
        System.out.println(new String(bytes4, StandardCharsets.UTF_16BE));
        System.out.println(new String(bytes5, "GBK"));
    }
}
